package config

import "github.com/docker/docker/client"

type DockerClientConfig struct {
	// host holds the server address to connect to
	Host string `json:",optional"`
	// version of the server to talk to.
	ApiVersion string `json:",optional"`
}

// NewDocker create new docker client
func NewDockerClient(c *DockerClientConfig) *client.Client {

	// default to local env
	if c.Host == "" {
		cli, err := client.NewClientWithOpts(client.FromEnv)
		if err != nil {
			panic(err)
		}
		return cli
	}

	// remote env
	cli, err := client.NewClientWithOpts(client.WithHost(c.Host), client.WithVersion(c.ApiVersion))
	if err != nil {
		panic(err)
	}
	return cli
}
